"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const request = require("request");
const utils = require("utils");
const index = require("../config/index.js");
const crypto = require("node:crypto");
function createContent(err) {
  let errStr = typeof err === "string" ? err : err.resMaker().errMsg;
  let content = [`### ${index.pushMessage.title}`, errStr];
  return content.join("\r\n");
}
async function toDingDingPush(content, atMobiles) {
  let timestamp = Date.now();
  let stringToSign = `${timestamp}
${index.dingDingSecret}`;
  const hmac = crypto.createHmac("sha256", index.dingDingSecret);
  hmac.update(stringToSign);
  const signature = hmac.digest("base64");
  let url = `${index.dingDingHook}&timestamp=${timestamp}&sign=${signature}`;
  let [pushErr, pushData] = await request.postRequest(url)(
    {
      at: {
        isAtAll: false,
        atMobiles
      },
      markdown: {
        title: index.pushMessage.title,
        text: content
      },
      msgtype: "markdown"
    },
    { contentType: "json" }
  );
  if (!utils.util.nilValue(pushErr)) {
    console.log("qw发送失败", pushErr);
    return [pushErr, void 0];
  }
  console.log("发送成功");
  return [void 0, pushData];
}
async function toQWPush(content) {
  let [err, data] = await request.postRequest(index.qwHook)(
    {
      msgtype: "markdown",
      markdown: {
        content
      }
    },
    { contentType: "json" }
  );
  if (!utils.util.nilValue(err)) {
    console.log("qw发送失败", err);
    return [err, void 0];
  }
  console.log("发送成功");
  return [void 0, data];
}
exports.createContent = createContent;
exports.toDingDingPush = toDingDingPush;
exports.toQWPush = toQWPush;
